import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
//创建仓库
export default new Vuex.Store({
    state: {
        datalist: []  ,//所有商品
    },
    mutations: {
        //拿到ajax的数据初始化商品组
        initlist(state, arr) {
            state.datalist = arr
        },
        //根据商品的id改变商品的数量
        changenum(state, param) {
            for (let obj of state.datalist) {
                for (let child of obj.foods) {
                    if (child.id == param.id) {
                        child.num += param.i
                        return
                    }
                }
            }
        },


    }

})